<?php
require_once 'Site/Filter.php';
require_once BASEPATH . 'apps/account/models/Account.php';

class Account_SignupController extends Zend_Controller_Action {
    public function indexAction() {
        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            if ($this->_validate()) {

            }
        }
        $this->view->title = 'Sign Up';
    }

    protected function _validate() {
        $_POST = Site_Filter::get($_POST, 'Magicquotes');
        $table = new Account();

        $username = Site_Filter::get($_POST['username'], 'Username');
        if (empty($username))
            $this->view->errorUsername = 'Preencha corretamente o campo usuário.';
        else if (!is_null($table->fetchRow($table->select()
            ->where('username = ?', $username)->limit(1))))
            $this->view->errorUsername = 'Usuário já existente.';

        $email = $_POST['email'];
        if (empty($email))
            $this->view->errorEmail = 'Preencha corretamente o campo endereço de email.';
        else if (!is_null($table->fetchRow($table->select()
            ->where('email = ?', $email)->limit(1))))
            $this->view->errorEmail = 'Endereço de email já existente.';

        return false;
    }
}
?>
